﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Net.NetworkInformation;
using Microsoft.Phone.Info;

namespace Tulde.MP3tunes
{
    public static class DeviceService
    {
        private static string _deviceId;


        public static string DeviceManufacturer
        {
            get{
                return "" + DeviceExtendedProperties.GetValue("DeviceManufacturer") ;
            }
        }
        public static string DeviceName
        {
             get{
                return "" + DeviceExtendedProperties.GetValue("DeviceName") ;
            }
        }
        public static string DeviceUniqueId
        {
             get{
                 var b = DeviceExtendedProperties.GetValue("DeviceUniqueId") as byte[];
                 try{
                     return Convert.ToBase64String(b);
                 }
                 catch{
                     return String.Empty;
                 }
            }
        }
        public static string DeviceFirmwareVersion
        {
             get{
                return "" + DeviceExtendedProperties.GetValue("DeviceFirmwareVersion") ;
            }
        }
        public static string DeviceHardwareVersion
        {
             get{
                return "" + DeviceExtendedProperties.GetValue("DeviceHardwareVersion") ;
            }
        }
        public static long DeviceTotalMemory
        {
             get{
                return (long) DeviceExtendedProperties.GetValue("DeviceTotalMemory") ;
            }
        }
        public static long ApplicationCurrentMemoryUsage
        {
             get{
                return (long)DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage") ;
            }
        }
        public static long ApplicationPeakMemoryUsage
        {
             get{
                return (long)DeviceExtendedProperties.GetValue("ApplicationPeakMemoryUsage") ;
            }
        }
        
        public static void QueryNetworkConnection(object state)
        {
            bool handled = false;

            // do not track if we are running in the emulator
            if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Device)
            {
                // track launch only if we have Wi-Fi currently enabled
                NetworkInterfaceType networkType = NetworkInterface.NetworkInterfaceType;
                if (networkType == NetworkInterfaceType.Wireless80211 ||
                    networkType == NetworkInterfaceType.Ethernet)
                {
                    // query device id on the worker thread to prevent slowing down the UI one
                  
              

                }
            }

        }
    }
}
